﻿using System;
using System.Linq;
using Solution.BusinessObject;
using Solution.CMS.MainDSTableAdapters;
using Solution.Core;
using Solution.Utilities;

namespace Solution.CMS
{
    public partial class Album : PageBase
    {
        readonly MainDS _mainDs = new MainDS();
        private MainDS.DetailContentsRow _detailContentsRow;
        private DetailContentsTableAdapter _detailContentsTableAdapter;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Request["act"] != null)
                {
                    var id = 0;

                    this.Action = Request["act"].ConvertToEnum<PageAction>();

                    if (Request["id"] != null)
                    {
                        id = Convert.ToInt32(Request["Id"]);
                    }

                    if (id == 0)
                    {
                        return;
                    }

                    if (Action == PageAction.Delete)
                    {
                        _detailContentsTableAdapter = new DetailContentsTableAdapter
                                                          {
                                                              Connection = CommonBO.SqlConnection
                                                          };
                        _detailContentsTableAdapter.Connection.Open();

                        _detailContentsTableAdapter.Fill(_mainDs.DetailContents);
                        _detailContentsRow = _mainDs.DetailContents.FindById(id);
                        if (_detailContentsRow != null)
                        {
                            _detailContentsRow.Delete();
                        }
                        _detailContentsTableAdapter.Update(_mainDs.DetailContents);
                    }

                    _detailContentsTableAdapter.Connection.Close();
                }
                var detailContents = CommonBO.MasterEDM.DetailContents.ToList();
                grdAlbum.DataSource = detailContents;
                grdAlbum.DataBind();
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex);
            }
        }
    }
}